<?php
/**
 * Created by PhpStorm.
 * User: xuzhong
 * Date: 2025/4/1
 * Time: 16:26
 */
namespace app\api\controller;
use think\Request;
use app\facade\Basic;
use  app\api\traits\ValidateTrait;
use think\exception\ValidateException;
class ProductProfit extends BaseController
{
    use ValidateTrait; // 使用 Trait
    ##员工信息
    protected $request;
    protected $service;
    protected $operator_id;
    protected $validationScenes  = [
        'profit'=>[
            'type'=>['require|integer', 'profit.type'],
            'pid'=>['integer', 'profit.pid'],
        ],
        'history'=>[
            'id'=>['require|integer', 'id'],
            'coinName'=>['require|string', 'coinName'],
            'number'=>['integer', 'number'],
        ]
    ];

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->service = new \app\api\service\Product();

    }

    /**
     * @describe 矿机收益计算
     * @author: xuzhong
     * @date: 2025-04-16 16:04:33
     * @param [] type
     * @return Renderable
     */
    public function profit(Request $request)
    {
        $params = $request->all();
        $lang = $this->request->header('think-lang');
        try {
            $this->autoValidate('profit');
            // 验证通过逻辑...
        } catch (ValidateException $e) {
            // 错误处理...
            $customErrors = $e->getMessage()??'';
            return Basic::json(['code'=>100001, 'message'=>$customErrors ]);
        }

        $res = $this->service->profit($params,$lang);

        return Basic::json($res);
    }

    /**
     * @describe 矿机收益计算 下拉列表
     * @author: xuzhong
     * @date: 2025-04-16 16:04:33
     * @param [] type
     * @return Renderable
     */
    public function select()
    {
        $lang = $this->request->header('think-lang');
        $res = $this->service->select($lang);

        return Basic::json($res);
    }

    /**
     * @describe 矿机历史收益
     * @author: xuzhong
     * @date: 2025-04-16 16:04:33
     * @param [] type
     * @return Renderable
     */
    public function historyIncome(Request $request)
    {
        $params = $request->all();
        try {
            $this->autoValidate('history');
            // 验证通过逻辑...
        } catch (ValidateException $e) {
            // 错误处理...
            $customErrors = $e->getMessage()??'';
            return Basic::json(['code'=>100001, 'message'=>$customErrors ]);
        }

        $res = $this->service->historyIncome($params);

        return Basic::json($res);
    }


}